﻿$(document).ready(function () {
    //headersize();
    $("#fr-searchvideo").submit(function () {
        var url = $("#urlvideo").val();
        $(".video-error").parent().remove();
        $(".video-result").parent().remove();
        $(".ajax-search").css("text-align", "center").html("<img src='/frontend/img/loading.gif' alt='Loading...' />");
        $.ajax({
            url: "/searchvideo",
            data: { url: url },
            type: 'POST',
            success: function (data) {
                //window.history.pushState(data, "Get link Youtube videos, download Youtube, download videos free", "/?url=" + url);
                $(".ajax-search").removeAttr("style").html(data);
            }
        });
        return false;
    });

    //init ajax load video
    if ($('.all-videos').length > 0) {
        $(".all-videos").css("text-align", "center").html("<img src='/frontend/img/loading.gif' alt='Loading...' />");
        $.ajax({
            url: "/othervideodownload",
            success: function (data) {
                $(".all-videos").removeAttr("style").html(data);
                $(".tabs-content .tab-detail").hide(); //Hide all content
                $("ul.tabs-list li:first").addClass("active").show(); //Activate first tab
                $(".tabs-content .tab-detail:first").show(); //Show first tab content
                //On Click Event
                $("ul.tabs-list li").click(function () {
                    $("ul.tabs-list li").removeClass("active"); //Remove any "active" class
                    $(this).addClass("active"); //Add "active" class to selected tab
                    $(".tabs-content .tab-detail").hide(); //Hide all tab content
                    var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
                    $(activeTab).fadeIn(); //Fade in the active content
                    return false;
                });
            }
        });
    }

    $(".navbar-toggle").click(function() {
        $(".header-right").toggleClass("menumobile");
    });
});

function CreateYoutube(title, alias, time) {
    $.ajax({
        url: "/createyoutube",
        data: { title: title, alias: alias, time: time }
    });
}

function headersize() {
    var win = $(window),
        header = $('#wrapper #header');

    if (!header.length) return;

    var set_height = function () {
        var scroll = $(window).scrollTop();
        if (scroll >= 1) {
            header.addClass('headersmaller');
        } else {
            header.removeClass('headersmaller');
        }
    };
    win.on('debouncedresize', function () { set_height(); });
    win.on('scroll', function () { set_height(); });
    set_height();
}